/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * addAnimationDialog.java
 *
 * Created on 14.05.2009, 14:53:34
 */

package peripheral.designer.wizard;

import java.awt.CardLayout;

/**
 *
 * @author Berni
 */
public class addAnimationDialog extends javax.swing.JDialog {

    //remember current panel
    private int currentIndex = 0;
    private int lastIndex = 2;

    /** Creates new form addAnimationDialog */
    public addAnimationDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

        //set prevbutton initially disabled
        prevButton.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cardPanel = new javax.swing.JPanel();
        preselectSensorPanel1 = new peripheral.designer.wizard.preselectSensorPanel();
        chooseAnimationPanel1 = new peripheral.designer.wizard.chooseAnimationPanel();
        createLocationsSymbolsPanel1 = new peripheral.designer.wizard.createLocationsSymbolsPanel();
        prevButton = new javax.swing.JButton();
        nextButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        cardPanel.setLayout(new java.awt.CardLayout());
        cardPanel.add(preselectSensorPanel1, "card2");
        cardPanel.add(chooseAnimationPanel1, "card3");
        cardPanel.add(createLocationsSymbolsPanel1, "card4");

        prevButton.setText("<");
        prevButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                prevButtonActionPerformed(evt);
            }
        });

        nextButton.setText(">");
        nextButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(506, Short.MAX_VALUE)
                .add(prevButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(nextButton)
                .add(28, 28, 28))
            .add(cardPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(cardPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(prevButton)
                    .add(nextButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
        CardLayout cl = ((java.awt.CardLayout)cardPanel.getLayout());

        if (currentIndex == 0) {
            prevButton.setEnabled(true);
        }

        if (currentIndex == (lastIndex - 1)) {
            nextButton.setText("Finish");
        }

        if (currentIndex == lastIndex) {
            //TODO finish was pressed
            this.setVisible(false);
            this.dispose();
        }
        else {
            currentIndex++;
            cl.next(cardPanel);
        }
    }//GEN-LAST:event_nextButtonActionPerformed

    private void prevButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevButtonActionPerformed

        CardLayout cl = ((java.awt.CardLayout)cardPanel.getLayout());

        if (currentIndex == 0) {
            return;
        }

        if (currentIndex == 1) {
            prevButton.setEnabled(false);
        }

        if (currentIndex == lastIndex) {
            nextButton.setText(">");
        }

        currentIndex--;
        cl.previous(cardPanel);
    }//GEN-LAST:event_prevButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                addAnimationDialog dialog = new addAnimationDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel cardPanel;
    private peripheral.designer.wizard.chooseAnimationPanel chooseAnimationPanel1;
    private peripheral.designer.wizard.createLocationsSymbolsPanel createLocationsSymbolsPanel1;
    private javax.swing.JButton nextButton;
    private peripheral.designer.wizard.preselectSensorPanel preselectSensorPanel1;
    private javax.swing.JButton prevButton;
    // End of variables declaration//GEN-END:variables

}
